package net.tarine.gastronomi.client.forms;

import net.tarine.gastronomi.client.AuthSingleton;
import net.tarine.gastronomi.client.HistoryMgr;
import net.tarine.gastronomi.client.IAuthenticatedWidget;
import net.tarine.gastronomi.client.UiSingleton;
import net.tarine.gastronomi.client.tables.DataModel;
import net.tarine.gastronomi.client.tables.ForumThreadTable;
import net.tarine.gastronomi.client.widgets.FramePanel;
import net.tarine.gastronomi.shared.AppConst;
import net.tarine.gastronomi.shared.to.ForumThreadTo;
import net.tarine.gastronomi.shared.to.GasTo;
import net.tarine.gastronomi.shared.to.GasUserTo;

import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Hyperlink;

public class ForumThreadListPage extends FramePanel implements IAuthenticatedWidget {

	private FlowPanel panel = null;
	//private GasUserTo user = null;
	
	public ForumThreadListPage() {
		AuthSingleton.get().authorizeWidget(this);
	}
	@Override
	public void unlockWidget(GasUserTo user) {
		//this.user=user;
		draw();
	}
	
	private void draw() {
		panel = new FlowPanel();
		Hyperlink createThreadLink = new Hyperlink("Crea discussione",
				HistoryMgr.FORUM_THREAD_EDIT+HistoryMgr.SEPARATOR_TOKEN+
				HistoryMgr.PARAM_ID+HistoryMgr.SEPARATOR_VALUES+AppConst.NEW_ITEM_ID);
		panel.add(createThreadLink);
		GasTo gas = UiSingleton.get().getGas();
		DataModel<ForumThreadTo> model = new ForumThreadTable.ForumThreadModel(gas);
		ForumThreadTable threadTable = new ForumThreadTable(model);
		panel.add(threadTable);
		this.set(panel, "Ultime discussioni");
	}
}
